/*
 *  AppComponent.h
 *  sdaProj
 *
 *  Created by tjmitche on 21/09/2010.
 *  Copyright 2010. All rights reserved.
 *
 */

#ifndef H_APPCOMPONENT
#define H_APPCOMPONENT

#include <juce.h>
#include <vector>

class AppComponent  :	public Component,
						public AudioIODeviceCallback,
						public ButtonListener,				//for the play and stop buttons
						public FilenameComponentListener,	//for the file select component
						public MidiInputCallback

{	
public:
	//==============================================================================
	AppComponent();
	~AppComponent();
	//==============================================================================
	void resized();
	void buttonClicked (Button* buttonThatWasClicked);
	void filenameComponentChanged (FilenameComponent*);
	void audioDeviceAboutToStart(AudioIODevice* device);
	void audioDeviceStopped();
	void audioDeviceIOCallback (const float** inputChannelData,
                                int totalNumInputChannels,
                                float** outputChannelData,
                                int totalNumOutputChannels,
                                int numSamples);
	AudioDeviceManager *getAudioDeviceManager(){return audioDeviceManager;}
	void handleIncomingMidiMessage(MidiInput*, const MidiMessage&);
	
	//==============================================================================
private:
	//==============================================================================
	//data members here
	
	//Juce members
	FilenameComponent *fileChooser;			
	
	TextEditor *textBox;
	TextButton *recordButton, *clearButton, *saveButton, *playButton;
	
	CriticalSection sharedMemory;
	
	//audio related
	AudioSampleBuffer *buffer;	//buffer to store the audio extracted from a file
	//buffer details
	long playPosition;	//keeps track of how far through SampleBuffer when playing back
	
	//audio related
	AudioDeviceManager *audioDeviceManager;	// this wraps the actual audio device
	
	bool recordOn;

};




#endif // H_APPCOMPONENT